package net.sf.calibur.test.tree;

import java.util.LinkedList;
import java.util.List;

class TreeNode {
	private TreeNode parent;
	private List<TreeNode> children;
	private int data;
	private long tick;
	
	public TreeNode(TreeNode parent, int data) {
		if (parent != null) {
			parent.addChild(this);
		}
		
		this.parent = parent;
		this.data = data;
		this.children = new LinkedList<TreeNode>();
		this.tick = 0;
	}
	
	public TreeNode(int data) {
		this(null, data);
	}
	
	public void addChild(TreeNode child) {
		children.add(child);
		child.setParent(this);
	}

	public TreeNode getParent() {
		return parent;
	}
	
	public void setParent(TreeNode parent) {
		this.parent = parent;
	}

	public List<TreeNode> getChildren() {
		return children;
	}

	public int getData() {
		return data;
	}

	public long getTick() {
		return tick;
	}
	
	public void setTick(long tick) {
		this.tick = tick;
	}
	
	public boolean isAllChildrenTraveled(long tick) {
		for (TreeNode child : children) {
			if (child.getTick() != tick) {
				return false;
			}
		}
		
		return true;
	}
	
	public boolean perform(long tick) {
		this.tick = tick;
		System.out.println(data);
		return true;
	}
}
